import { Controller, Get, Post, Body, Patch,Query,Req, Param, Delete,UseGuards} from '@nestjs/common';
import { RoleService } from './role.service';
import { CreateRoleDto,UpdateRoleDto,ListRoleDto } from './dto';
import { LoginGuard } from '../../../login/login.guard';

@Controller('system/role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @UseGuards(LoginGuard)
  @Post('/add')
  async add(@Body() role: CreateRoleDto) {
    return this.roleService.add(role);
  }

  @UseGuards(LoginGuard)
  @Get('/findAll')
  findAll(@Query() query: ListRoleDto, @Req() req) {
    if(query&&query.pageNum){
      return this.roleService.findPage(query,req);
    }else{
      return this.roleService.find();
    }
  }

  @UseGuards(LoginGuard)
  @Get('/findOne')
  findOne(@Param('id') id: string) {
    return this.roleService.findOne(id);
  }

  @UseGuards(LoginGuard)
  @Post('/update')
  update(@Body() updateRoleDto: UpdateRoleDto) {
    return this.roleService.update(updateRoleDto);
  }

  @UseGuards(LoginGuard)
  @Post('/remove')
  remove(@Body() ids: string[]) {
    return this.roleService.remove(ids);
  }

  @UseGuards(LoginGuard)
  @Post('/addRoleMenu')
  addRoleMenu(@Body('roleid') roleid:string,@Body('menuids') menuids:string[] ) {
    return this.roleService.addRoleMenu(roleid,menuids);
  }

}
